package inabit.inabitcompiler.productions.fuzzy;

import inabit.compiler.parser.grammar.NonTerminal;
import inabit.compiler.parser.grammar.Production;
import inabit.compiler.parser.grammar.Symbol;
import inabit.compiler.parser.grammar.Terminal;
import inabit.fuzzy.data.FuzzySet;
import inabit.inabitcompiler.lexical.InabitTokenClass;
import inabit.inabitcompiler.parser.InabitSemanticAction;

import java.io.File;

/**Fs' -> import (string_cte) as id;FS''*/
/**@author Rafael Rocha*/
public class Fs1_Rule extends Production{
	private Terminal path;
	private Terminal id;
	public Fs1_Rule() {
		super("Fs'");
	}

	@Override
	protected Symbol[] production(NonTerminal nonTerminal) {
		path = new Terminal(InabitTokenClass.STRING_CTE);
		id = new Terminal(InabitTokenClass.ID);
		Symbol[] symbols = {
			new Terminal(InabitTokenClass.IMPORT),
			new Terminal(InabitTokenClass.OPEN_PARENTHESIS),
			path,
			new Terminal(InabitTokenClass.CLOSE_PARENTHESIS),
			new Terminal(InabitTokenClass.AS),
			id,
			new Terminal(InabitTokenClass.SEMI_COLON),
			new InabitSemanticAction(nonTerminal) {
				
				@Override
				public void execute() throws Exception {
					
					FuzzySet set = FuzzySet.loadAndRename(
							new File(path.getValue()),
							id.getValue());
					
					addFuzzySet(set);
				}
			},
			new NonTerminal("Fs''")
		};
		return symbols;
	}
	
	

}

